using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tKitchen
{
    public partial class RecipeCategoryInput : Form
    {
        RecipeCategoryPresenter presenter;

        public RecipeCategoryInput(RecipeCategoryPresenter presenterIn)
        {
            InitializeComponent();
            presenter = presenterIn;

        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            List<RecipeCategory> catList = (List<RecipeCategory>)dataGridView1.DataSource;
            RecipeCategory tempCat = catList[e.RowIndex];
            presenter.UpdateCategory(tempCat);
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            //check for empty boxes first
            //any of them could be null, but make sure then put somehting in
            if (textBoxDescr.Text != "" || textBoxName.Text != "")
            {

                presenter.AddCategory(textBoxName.Text, textBoxDescr.Text);
                textBoxName.Clear();
                textBoxDescr.Clear();
                textBoxName.Focus();
            }
        }

        public void SetDataSource(List<RecipeCategory> catList)
        {
            dataGridView1.DataSource = catList;
        }


        internal void RefreshGrid()
        {
            dataGridView1.Refresh();
        }

    }
}